﻿using BG.DAL.Model;
using BG.DAL.Context;
using System.Collections.Generic;
using System;
using System.Data;
using System.Data.Entity;

namespace BG.DAL.SQLDAL
{
    public class UserManager
    {
        public static User GetById(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                User model = db.Users.Find(id);
                return model;
            }
        }

        public static void Create(User model)
        {
            using (DataContext db = new DataContext())
            {
                db.Users.Add(model);
                db.SaveChanges();
            }
        }

        public static void Edit(User model)
        {
            using (DataContext db = new DataContext())
            {
                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
            }
        }

        public static void Delete(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                User model = db.Users.Find(id);
                db.Users.Remove(model);
                db.SaveChanges();
            }
        }
    }
}
